﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace FBA.Client.Converters
{
    /// <summary>
    /// 价格单位转换器，列表显示的时候，把后台的分除以100显示
    /// </summary>
    public partial class PriceConverter : IValueConverter
    {
        
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null && value != DBNull.Value)
            {
                return Convert.ToDecimal(value)/100;
            }
            else
            {
                return null;
            }
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            decimal result = 0;
            if (decimal.TryParse(Convert.ToString(value), out result))
            {
                return result * 100;
            }
            else
            {
                return value;
            }
        }
    }
}
